﻿$(function () {
    $('.query').click(function () {
        var code = $.trim($('#code').val());
        var yzm = $.trim($('#yzm').val());
        if (!code) {
            alert('请输入一次校验码');
        } else if (!yzm) {
            alert('请输入验证码');
        } else {
            $.ajax({
                type: "POST",
                url: "/tools/code_ajax.ashx?action=codequery",   //提交的页面/方法名
                data: { "code": code, "yzm": yzm },
                dataType: "json",               //类型
                //contentType: "application/json; charset=utf-8",
                success: function (data) {
                    //返回的数据用data.d获取内容                       
                    window.location.href = 'item.html!' + encodeURI(code);
                },
                error: function (err) {
                    alert('验证码错误！');
                }
            });
        }
        return false;
    });
    //刷新验证码 
    $('#imageCheck').click(function () {
        ChangeCodeImg();
    });
});

//随机数方法
rnd.today = new Date();
rnd.seed = rnd.today.getTime();
function rnd() {
    rnd.seed = (rnd.seed * 9301 + 49297) % 233280;
    return rnd.seed / (233280.0);
};
function rand(number) {
    return Math.ceil(rnd() * number);
};
function imageLoaded() {
    document.getElementById("btnSubmit").disabled = "";
}
function ChangeCodeImg() {
    var a = document.getElementById("imageCheck");
    a.src = "/tools/verify_code.ashx?" + rand(10000000);
    document.getElementById("btnSubmit").disabled = true;
    document.getElementById("yzm").value = "";
}